package collection2;

import collection.Point;
import com.sun.xml.internal.ws.policy.privateutil.PolicyUtils;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;

public class List排序 {
    public static void main(String[] args) {
        List<String>ji=new LinkedList<>();
        ji.add("wo");
        ji.add("java");
        ji.add("c++");
        ji.add("php");
        ji.add("王杰经");
        ji.add("拉链经味味");

        Collections.sort(ji,(o1, o2) -> o1.length()-o2.length());
        System.out.println(ji);

        List<Integer> i=new LinkedList<>();
        Random random = new Random();
        for (int j=0;j<10;j++){
            i.add(0, random.nextInt(100)+1);
        }
        System.out.println("原集合"+i);
        Collections.sort(i);
        System.out.println("升序集合小到大"+i);
        Collections.reverse(i);
        System.out.println("降序集合大到小"+i);

        List<Point> p=new LinkedList<>();
        p.add(new Point(1,3));
        p.add(new Point(5,3));
        p.add(new Point(9,5));
        p.add(new Point(5,98));
        p.add(new Point(17,3));
        System.out.println(p);
        Collections.sort(p,(o1, o2) -> {
            int len1= o1.getX()* o1.getX()+ o1.getY()* o1.getY();
            int len2= o2.getX()* o2.getX()+ o2.getY()* o2.getY();
//            return len1-len2;//升序 小到大
            return len2-len1;//降序 大到小
        });

        System.out.println(p);
    }
}
